import Vue from 'vue'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import store from './store'
import Element from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// 分页组件
import Pagination from "@/components/Pagination";

// 全局组件挂载
Vue.use(Element);
Vue.component('Pagination', Pagination);
Vue.prototype.$store = store;
Vue.prototype.$axios = axios;
Vue.prototype.$bus = new Vue();
Vue.config.productionTip = false;

// 拦截器
router.beforeEach((to, from, next) => {
        if (to.meta.requireAuth) {
            if (store.state.user.username) {
                next()
            } else {
                next({
                    path: '/login',
                    query: {redirect: to.fullPath}
                })
            }
        } else {
            next()
        }
    }
)

new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
})
